﻿using BW.WMS.CodeEnum;
using BW.WMS.Model;
using BW.WMS.RBAC;
using BW.WMS.WCL.DTO;
using BW.WMS.XKY.DTO.Input;
using BW.WMS.XKY.DTO.Output;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Application.Services;
using Volo.Abp.Domain.Repositories;
using Volo.Abp.ObjectMapping;
using static Volo.Abp.Identity.IdentityPermissions;

namespace BW.WMS.WCL
{
    public class Me_StCurService : ApplicationService, IMe_StCurService
    {
           public readonly IRepository<Me_StCur, Guid> _me_StCurRepository;

        public Me_StCurService(IRepository<Me_StCur, Guid> me_StCurRepository)
        {
            _me_StCurRepository = me_StCurRepository;
        }

        public async Task<ApiResult<int>> CreateAsync(CreateUpdateMe_Stcur input)
        {
            var stCur = ObjectMapper.Map<CreateUpdateMe_Stcur, Me_StCur>(input);
              await _me_StCurRepository.InsertAsync(stCur);
            return new ApiResult<int>()
            {
                Code = ApiEnum.Success,
                Data = 1,
                Message = "添加成功"
            };
        }

        public async Task<ApiResult<int>> DeleteAsync(Guid id)
        {
             var stCur =await _me_StCurRepository.GetAsync(id);
            await _me_StCurRepository.DeleteAsync(stCur);
            return new ApiResult<int>()
            {
                Code = ApiEnum.Success,
                Data = 1,
                Message = "删除成功"
            };
        }

        public async Task<ApiResult<List<Me_StCurDto>>> GetListAsync()
        {
            var stCurs =await _me_StCurRepository.GetQueryableAsync();
            var stCursDto = ObjectMapper.Map<List<Me_StCur>,List<Me_StCurDto>>(stCurs.ToList());
            return new ApiResult<List<Me_StCurDto>>()
            {
                Code = ApiEnum.Success,
                Data = stCursDto,
                Message = "查询成功"
            };
            
        }

        public async Task<ApiResult<int>> UpdateAsync(Guid id, CreateUpdateMe_Stcur input)
        {
            var stCur = await _me_StCurRepository.GetAsync(id);
            // 这里可以用 ObjectMapper 进行映射，或者手动赋值
            ObjectMapper.Map(input, stCur);
            await _me_StCurRepository.UpdateAsync(stCur);
            return new ApiResult<int>()
            {
                Code = ApiEnum.Success,
                Data = 1,
                Message = "修改成功"
            };
        }
    }
}
